package com.jinboe.comm.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	private static SimpleDateFormat formatterTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private static SimpleDateFormat formatterDate = new SimpleDateFormat("yyyy-MM-dd");
	public static Date getNowDate() {
	   Date currentTime = new Date();
	   String dateString = formatterTime.format(currentTime);
	   ParsePosition pos = new ParsePosition(8);
	   Date currentTime_2 = formatterTime.parse(dateString, pos);
	   return currentTime_2;
	}
	
	public static String getStringDate() {
	   Date currentTime = new Date();
	   String dateString = formatterTime.format(currentTime);
	   return dateString;
	}
	public static String getStringDateShort() {
	   Date currentTime = new Date();
	   String dateString = formatterDate.format(currentTime);
	   return dateString;
	}
	
	public static String getTimeShort() {
	   Date currentTime = new Date();
	   String dateString = formatterTime.format(currentTime);
	   return dateString;
	}
	public static String getDate() {
		   Date currentTime = new Date();
		   String dateString = formatterTime.format(currentTime);
		   return dateString;
		}
	public static Date stringToDate(String strDate) {
	   ParsePosition pos = new ParsePosition(0);
	   Date strtodate = formatterDate.parse(strDate, pos);
	   return strtodate;
	}
	public static String dateToString(java.util.Date dateDate) {

	   String dateString = formatterDate.format(dateDate);
	   return dateString;
	}
	/**
	   * 将短时间格式时间转换为字符串 yyyy-MM-dd
	   * 
	   * @param dateDate
	   * @param k
	   * @return
	   */
	public static String dateToStr(java.util.Date dateDate) {
	   String dateString = formatterTime.format(dateDate);
	   return dateString;
	}
	public static long compareTodate(String DATE1) {  
		try {
			Date dt1 = formatterDate.parse(DATE1);  
			Date dt2 = formatterDate.parse(getDate());  
			return dt1.getTime()-dt2.getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return 0L;
	}
	public static int compare_date(String DATE1, String DATE2) {  
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm"); 
		try {
			Date dt1 = df.parse(DATE1);  
			Date dt2 = df.parse(DATE2);  
			if (dt1.getTime() > dt2.getTime()) {  
				System.out.println("dt1 在dt2前");  
				return 1;  
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return 0;
	}
}